#include "probability.h"
#include <stdio.h>

double bernouli_probability = 0.5;

//Initializes the random vars engine with seed and Bernoulli probability
void InitRandomizer(int seed, double bernouli_p) {
	
	//Set the bernouli process parameter
	bernouli_probability = bernouli_p;

	//Initialize randomizer with the seed
	srand(seed);
}
	
//Returns next result in Bernoulli process
int NextBernouliResult() {

	double res = (double)rand() / RAND_MAX;
	return (res < bernouli_probability) ? 1 : 0;
}

//Returns a number between 0 and N, each option has equal probability (1/N)
int NextUniformDistributedNumber(int i, int N) {
	return rand() % N;
}

/* Simulates diagonal distribution:
						2/3	if j = i
Pr[result = j | i] = {	1/3	if j = i + 1 mod N
						0	otherwise
*/
int NextDiagonalDistributedNumber(int i, int N) {
	double res = (double)rand() / RAND_MAX;
	return (res < (2.0/3.0) ? i : ((i + 1 ) % N));
}